﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

namespace UI
{
    public class RushAdditionViewPage : Page 
    {
        public UILabel hpAddLabel;
        public UILabel attAddLabel;
        public UILabel phyDefAddLabel;
        public UILabel magdefAddLabel;
        public UILabel hitAddLabel;
        public UILabel dodgeAddLabel;
        public UILabel criAddLabel;
        public UILabel antiCriAddLabel;
        public UILabel damageAddLabel;
        public UILabel damageReduceLabel;

        public List<UITweener> tweeners;


        protected override void DoOpen()
        {
            Clear();
            ProtoBuf.Message.CSRushAdditionView msg = new ProtoBuf.Message.CSRushAdditionView();
            NetAPI.SendHttp(ProtoBuf.Message.OpDefine.CSRushAdditionView, msg, (pack, b)=>{
                if (b)
                {
                    ProtoBuf.Message.SCRushAdditionView _msg = pack.kBody as ProtoBuf.Message.SCRushAdditionView;
                    Refresh(_msg.prop);
                }
            });
            foreach (var tweener in tweeners)
            {
                if (tweener != null)
                {
                    tweener.ResetToBeginning();
                    tweener.PlayForward();
                }
            }
        }


        void Clear() {
            hpAddLabel.gameObject.SetActive(false);
            attAddLabel.gameObject.SetActive(false);
            phyDefAddLabel.gameObject.SetActive(false);
            magdefAddLabel.gameObject.SetActive(false);
            hitAddLabel.gameObject.SetActive(false);
            dodgeAddLabel.gameObject.SetActive(false);
            criAddLabel.gameObject.SetActive(false);
            antiCriAddLabel.gameObject.SetActive(false);
            damageAddLabel.gameObject.SetActive(false);
            damageReduceLabel.gameObject.SetActive(false);
        }

        void Refresh(ProtoBuf.Message.BaseProp prop) {
            hpAddLabel.text = GetAddStr(prop.perhp);
            attAddLabel.text = GetAddStr(prop.peratt);
            phyDefAddLabel.text = GetAddStr(prop.perpdef);
            magdefAddLabel.text = GetAddStr(prop.permdef);
            hitAddLabel.text = GetAddStr(prop.hit);
            dodgeAddLabel.text = GetAddStr(prop.dodge);
            criAddLabel.text = GetAddStr(prop.cri);
            antiCriAddLabel.text = GetAddStr(prop.antiCri);
            damageAddLabel.text = GetAddStr(prop.damageAdd);
            damageReduceLabel.text = GetAddStr(prop.damageReduce);

            hpAddLabel.gameObject.SetActive(true);
            attAddLabel.gameObject.SetActive(true);
            phyDefAddLabel.gameObject.SetActive(true);
            magdefAddLabel.gameObject.SetActive(true);
            hitAddLabel.gameObject.SetActive(true);
            dodgeAddLabel.gameObject.SetActive(true);
            criAddLabel.gameObject.SetActive(true);
            antiCriAddLabel.gameObject.SetActive(true);
            damageAddLabel.gameObject.SetActive(true);
            damageReduceLabel.gameObject.SetActive(true);
        }

        string GetAddStr(double value) {
            return string.Format("+{0}%", (value * 100).ToString("f0"));
        }

    }
}